import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore(
	'counter',
	() => {
		// 定义 state
		let count = ref(0)

		// 定义 getters
		const double = computed(() => count.value * 2)

		// 定义 actions
		const increment = () => {
			count.value++
		}

		const decrement = () => {
			count.value--
		}

		//实现传入加值
		const addNum = (num: number) => {
			count.value += num
		}

		// 千万不要忘记这里要 return
		return { count, double, increment, decrement, addNum }
	},
	// 使用unistorage会将数据都存入到硬盘里面
	// { unistorage: true } //这个是将数据全部都存起来
	{
		unistorage: {
			key: 'doctor-key',
			paths: ['count'],
		},
	} //可以用这种办法实现部分存储
)
